﻿<Page
    x:Class="MusicExplorer.Views.RootView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:caliburn="using:Caliburn.Micro"
    xmlns:converters="using:MusicExplorer.Converters"
    xmlns:toolkit="using:WinRTXamlToolkit.Controls">

    <Page.Resources>
        <converters:MediaStateToPauseVisibilityConverter x:Key="StatePauseConterter" />
        <converters:MediaStateToPlayVisibilityConverter x:Key="StatePlayConverter" />
        <converters:TrackTypeToSliderVisibilityConverter x:Key="TrackTypeToSliderVisibilityConverter" />
        <converters:TrackTypeToWebViewVisibilityConverter x:Key="TrackTypeToWebViewVisibilityConverter" />
        <converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
        <converters:TrackTypeToYoutubeVisibilityConverter x:Key="TrackTypeToYoutubeVisibilityConverter" />
        <converters:UriTo100x100BitmapConverter x:Key="UriTo100x100BitmapConverter" />
    </Page.Resources>

    <Grid Background="{StaticResource DefaultApplicationBackground}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="92" />
        </Grid.RowDefinitions>
        
        <MediaElement IsFullWindow="False" AutoPlay="False" caliburn:Message.Attach="[Event MediaOpened] = [SetCurrentTrackAsRead]"
                      MediaOpened="mediaElement_MediaOpened" MediaFailed="mediaElement_MediaFailed"
                      x:Name="mediaElement" Visibility="Collapsed" />
        
        <Frame Loaded="Frame_Loaded" DataContext="{x:Null}" x:Name="currentFrame" Margin="0">
            <Frame.ContentTransitions>
                <TransitionCollection>
                    <EntranceThemeTransition />
                </TransitionCollection>
            </Frame.ContentTransitions>
        </Frame>

        <Border Grid.Row="2" BorderThickness="0" Background="{StaticResource DefaultPlayerBackground}" >
            <Grid Visibility="{Binding SelectedTrack, Converter={StaticResource NullToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="50" />
                    <ColumnDefinition Width="400" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <Border BorderBrush="{StaticResource DefaultApplicationSecondaryForeground}"
                        BorderThickness="1" Margin="5">
                    <Image Source="{Binding SelectedTrack.Artwork, Converter={StaticResource UriTo100x100BitmapConverter}}"
                           VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="UniformToFill" />
                </Border>
                <StackPanel Grid.Column="1" Margin="5" Orientation="Vertical">
                    <TextBlock Text="{Binding SelectedTrack.DisplayName}" VerticalAlignment="Top"
                               FontSize="14" LineHeight="15" Margin="0, -2, 0, 0"
                               Style="{StaticResource DefaultApplicationTextBlockStyle}" TextWrapping="Wrap"
                               Foreground="{StaticResource DefaultApplicationBackground}" />
                    <TextBlock Text="{Binding SelectedTrack.DisplayComposers}" VerticalAlignment="Top"
                               Style="{StaticResource DefaultApplicationTextBlockStyle}" TextWrapping="NoWrap"
                               TextTrimming="CharacterEllipsis" FontSize="14" LineHeight="15"
                               Foreground="{StaticResource DefaultApplicationSecondaryForeground}" />
                    <TextBlock Text="{Binding SelectedTrack.DisplayRemixers}" VerticalAlignment="Top"
                               TextTrimming="CharacterEllipsis" FontSize="14" LineHeight="15"
                               Style="{StaticResource DefaultApplicationTextBlockStyle}" TextWrapping="NoWrap"
                               Foreground="{StaticResource DefaultApplicationSecondaryForeground}" />
                </StackPanel>
                <ProgressRing IsActive="False" Height="30" Width="30" Grid.Column="2" x:Name="progressTrack"
                              Foreground="{StaticResource DefaultApplicationBackground}" />
                <Slider Name="timelineSlider" Minimum="0" Grid.Column="3" IsTabStop="False" PointerEntered="timelineSlider_PointerEntered"
                        VerticalAlignment="Center" VerticalContentAlignment="Center" Style="{StaticResource SliderTrackStyle}"
                        PointerCaptureLost="timelineSlider_PointerCaptureLost" IsThumbToolTipEnabled="False" />
                <!--Visibility="{Binding SelectedTrack.TrackType, Converter={StaticResource TrackTypeToSliderVisibilityConverter}}"-->
                <WebView x:Name="webView" Grid.Column="4" Height="40" VerticalAlignment="Center"
                         Visibility="Collapsed" DefaultBackgroundColor="#1D1D1D" LoadCompleted="webView_LoadCompleted" />
                <!-- Visibility="{Binding SelectedTrack.TrackType, Converter={StaticResource TrackTypeToWebViewVisibilityConverter}}"-->
                <!-- caliburn:Message.Attach="[Event LoadCompleted] = [SetCurrentTrackAsRead]"-->
                
                <StackPanel Orientation="Horizontal" Margin="10, 0, 20, 0" Grid.Column="4">
                            <!--Visibility="{Binding SelectedTrack.TrackType, Converter={StaticResource TrackTypeToSliderVisibilityConverter}}" >-->
                    <Button Style="{StaticResource PauseButtonStyle}" Click="Pause_Click"
                        VerticalAlignment="Center" Margin="0, 0, 0, 0"
                        Visibility="{Binding ElementName=mediaElement, Path=CurrentState, Converter={StaticResource StatePauseConterter}}" />
                    <Button Style="{StaticResource PlayButtonStyle}" Click="Play_Click"
                        VerticalAlignment="Center" Margin="0, 0, 0, 0"
                        Visibility="{Binding ElementName=mediaElement, Path=CurrentState, Converter={StaticResource StatePlayConverter}}" />
                </StackPanel>
                
                <Grid Grid.Column="5">
                    <StackPanel Orientation="Horizontal">
                        <AppBarButton Icon="Globe" Label="{Binding SelectedTrack.WebButtonLabel}"
                              Visibility="{Binding SelectedTrack, Converter={StaticResource NullToVisibilityConverter}}" 
                              caliburn:Message.Attach="[Event Click] = [OpenTrackUrl]" />
                        <AppBarButton Icon="Find" Label="Youtube" caliburn:Message.Attach="[Event Click] = [SearchOnYoutube]"
                              Visibility="{Binding SelectedTrack.TrackType, Converter={StaticResource TrackTypeToYoutubeVisibilityConverter}}" />
                    </StackPanel>
                </Grid>
                
            </Grid>
        </Border>
    </Grid>
</Page>
